package in.muton.edushare.components.forms.usersettings;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.auth.api.Authentication;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import com.edushare.common.vo.Users;

public class NotifyForm extends Panel {

	private static final Log log = LogFactory.getLog(NotifyForm.class);

	public NotifyForm(String id, IModel<Users> aModel) {
		super(id, aModel);
		model = aModel;
		auth = new Authentication(model.getObject(), EduShareSession.get()
				.getLoggedInUser());

		Form<Void> f = new Form<Void>("notifyPanel") {
			@Override
			public void onSubmit() {
				model.getObject().setSettings(auth.getString());
				EduShareSession.get().getSessionORMInterface()
						.commitAllChanges();
			}

			private static final long serialVersionUID = 1L;
		};
		add(f);
		f.setDefaultModel(new CompoundPropertyModel<NotifyForm>(this));
		f.add(new CheckBox("mHP"));
		f.add(new CheckBox("eHP"));
		f.add(new CheckBox("fHP"));
		f.add(new CheckBox("pHP"));
		f.add(new CheckBox("aHP"));
	}

	public boolean getAHP() {
		return auth.getSetting(Authentication.NOTIFY_ASS).equals("t");
	}

	public void setAHP(boolean aHP) {
		String t = aHP ? Authentication.TRUE : Authentication.FALSE;
		auth.changeSetting(Authentication.NOTIFY_ASS, t);
	}

	public boolean getFHP() {
		return auth.getSetting(Authentication.NOTIFY_FIL).equals("t");
	}

	public void setFHP(boolean fHP) {
		String t = fHP ? Authentication.TRUE : Authentication.FALSE;
		auth.changeSetting(Authentication.NOTIFY_FIL, t);
	}

	public boolean getPHP() {
		return auth.getSetting(Authentication.NOTIFY_POL).equals("t");
	}

	public void setPHP(boolean pHP) {
		String t = pHP ? Authentication.TRUE : Authentication.FALSE;
		auth.changeSetting(Authentication.NOTIFY_POL, t);
	}

	public boolean getMHP() {
		return auth.getSetting(Authentication.NOTIFY_MSG).equals("t");
	}

	public void setMHP(boolean mHP) {
		String t = mHP ? Authentication.TRUE : Authentication.FALSE;
		auth.changeSetting(Authentication.NOTIFY_MSG, t);
	}

	public boolean getEHP() {
		return auth.getSetting(Authentication.NOTIFY_EVT).equals("t");
	}

	public void setEHP(boolean eHP) {
		String t = eHP ? Authentication.TRUE : Authentication.FALSE;
		auth.changeSetting(Authentication.NOTIFY_EVT, t);
	}

	public IModel<Users> getModel() {
		return model;
	}

	public void setModel(IModel<Users> model) {
		this.model = model;
	}

	Authentication auth = null;
	private static final long serialVersionUID = 3694691967712771984L;
	private IModel<Users> model;
}
